Release 10.1A: OpenEdge Development:
Progress 4GL Handbook


Creating a dynamic query

Now take a look at getQuery. It first creates a dynamic query, to pass back as an OUTPUT parameter (hence the naming convention ohQuery):

  /* Create the query and assign the handle to the output parameter variable */ 
  CREATE QUERY ohQuery.   

Then it walks through the list of buffer names passed in, creates a dynamic buffer for each one, and adds each buffer to the query:

  /* Create a buffer for this table */ 
    CREATE BUFFER hTable FOR TABLE cTableName. 
    /* Add this buffer to the query */ 
    ohQuery:ADD-BUFFER(hTable). 

Finally, it prepares the dynamic query using the FOR EACH statement passed in:

  /* Prepare the query */ 
  ohQuery:QUERY-PREPARE(icForEach). 

This is a general-purpose mechanism for creating not only any dynamic query, but also all the buffers it uses, without defining anything in advance. It’s prepared to work against any list of tables for any database.

It’s also a good idea to look at the cleanupQuery function, which reminds you to always delete dynamic objects when you’re done with them. It deletes the query and then all the dynamic buffers the query used:

  /* Now delete the query object */ 
     deleteObject(hQuery). 
  /* Now iterate through the string */ 
     DO iCount = 1 TO NUM-ENTRIES(cBuffers): 
  /* convert each entry to a handle */ 
     hBuffer = WIDGET-HANDLE(ENTRY(iCount,cBuffers)). 
     /* and pass the handle to deleteObject */ 
        deleteObject(hBuffer). 
     END. 


Copyright © 2005 Progress Software Corporation
www.progress.com
Voice: (781) 280-4000
Fax: (781) 280-4095